<template>
  <div>
    <el-form label-width="150px">
      <el-form-item label="模板展示">
        <el-tag type="info">excel模板要求-></el-tag>
        <el-tag>
          <i class="el-icon-download"></i>
          <a href="/static/write.xlsx">下载模板文件</a>
        </el-tag>
      </el-form-item>

      <!-- 上传 -->
      <el-form-item label="上传文件">
        <el-upload
          ref="upload"
          name="file"
          :action="BASE_API + '/eduservice/subject/addSubject'"
          :on-success="fileUploadSuccess"
          :on-error="fileUploadError"
          :disabled="importBtnDisabled"
          :auto-upload="false"
          :limit="1"
          accept=".xls, .xlsx"
        >
          <el-button slot="trigger" size="small" type="primary"
            >选取文件</el-button
          >
          <el-button
            :loading="loading"
            style="margin-left: 10px"
            size="small"
            type="success"
            @click="submitUpload"
            >上传到服务器</el-button
          >
          <div slot="tip" class="el-upload__tip">
            上传过去-意味着杜杜要操作了！
          </div>
        </el-upload>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "SaveSubject",
  data() {
    return {
      BASE_API: process.env.BASE_API, //基本API,
      loading: false, //默认不加载
      importBtnDisabled: true,
    };
  },
  methods: {
    //点击上传
    submitUpload() {
      //利用vue 上传提交
      this.loading = true;
      this.$refs.upload.submit();
    },
    //上传成功
    fileUploadSuccess() {
      this.loading = false;
      this.$message({
        type: "success",
        message: "添加课程分类成功",
      });
      this.$router.push({ path: "/subject/list" });
    },

    //上传失败
    fileUploadError() {
      this.loading = false;
      this.$message({
        type: "error",
        message: "添加课程分类失败",
      });
    },
  },
};
</script>

<style >
</style>